/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Action;

import Game.NewGame;
import IO.Utils;
import IO.models.PlayerConfig;
import Inrterface.Info;
import Inrterface.Interface;
import Inrterface.Messages;
import Map.MapLevel;
import Map.Map;
import Monsters.Monster;
import Monsters.Monsters;
import Player.PlayerInterface;
import java.io.FileNotFoundException;
import java.io.IOException;
import jcgame.Main;
import jcurses.system.Toolkit;
import net.slashie.libjcsi.CharKey;

/**
 *
 * @author insane
 */
public class Actions {

    public static void main(String[] p) throws FileNotFoundException, ClassNotFoundException, IOException, InterruptedException {
        while (!NewGame.StartGame());
        Main.csi.cls();
        PlayerConfig.getInstance().save();
        new Actions().run();
    }

    public void run() throws FileNotFoundException, ClassNotFoundException, IOException, InterruptedException {

        Utils ut = new Utils();
        Interface inf = new Interface();

        //time check
        ut.timeCheck("load interface");
        //time check

        Map map = MapLevel.getInstance().getMap();

        char[][] ismap = map.getMap();
        Main.csi.cls();
        Main.csi.saveBuffer();
        boolean exit = false;

        //time check
        ut.timeCheck("load map");
        //time check

        while (!exit) {

            Main.csi.cls();
            Main.csi.restore();

            inf.draw();
            map.drawMap();
            Monsters.getMonsterToMap(map);
            Info.draw(map);
            Messages.getInstance().draw();

            Main.csi.refresh();
            Utils.seeEvents();

            int key = Main.csi.inkey().code;

            PlayerConfig.getInstance().getPlayer(NewGame.getPlayer().getName()).setStep(NewGame.getPlayer().getStep() + 1);

            if (KeyPressed.getCheckPressed(map, key) == null) {
                exit = true;
            }


            See.checkSee(map.x, map.y, ismap);

            Events.getInstance().checkEvents(map);


            map = MapLevel.getInstance().getMap();

            ismap = map.getMap();
        }

        Main.csi.print(1, 20, "Press space to continue");
        Main.csi.refresh();
        Main.csi.waitKey(CharKey.SPACE);
        Toolkit.shutdown();
        System.exit(0);
    }
}
